package org.digitarts.rtms.spring.collectors.jms;

import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.Session;

public class SimpleSyntehticMessageFactory implements ISyntehticMessageFactory
{
	protected Properties	systemProperties	= null;
	protected String		name				= "SystemPropertiesMapMessage";
	protected int			messageCount		= 1;

	public int getMessageCount()
	{
		return messageCount;
	}

	public void setMessageCount(int messageCount)
	{
		this.messageCount = messageCount;
	}

	public SimpleSyntehticMessageFactory()
	{
		systemProperties = System.getProperties();
	}

	@Override
	public Message[] createMessage(Session session) throws JMSException
	{
		List<Message> messages = new ArrayList<Message>(messageCount);
		for (int i = 0; i < messageCount; i++)
		{
			MapMessage message = session.createMapMessage();
			for (Object key : systemProperties.keySet())
			{
				message.setString(key.toString(), systemProperties.getProperty(key.toString()));
			}
			messages.add(message);
		}
		return messages.toArray(new Message[messages.size()]);
	}

	public String getName()
	{
		return name;
	}

	public void setName(String name)
	{
		this.name = name;
	}

}
